import java.net.UnknownHostException;


/**
 * Main entry point for program
 * @author jwallrab
 *
 */
public class dsfinal {
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		System.out.println("*** Party Description ***");
		
		//java dsfinal -type [dealer,server] -k 5 -secret 1234 -port 8080
		//SECRET MUST BE A NUMBER!
		String type = "";
		int port = -1;
		String secret = "";
		int k = -1;
		
		try {
			String host = java.net.InetAddress.getLocalHost().getHostName();
			System.out.println("Hostname: " + host);
		} catch (UnknownHostException e) {
		}
		
		for(int i = 0; i < args.length; ++i){
			if(args[i].equals("-type")){
				type = args[i+1];
				if(!type.equals("dealer") && !type.equals("server")){
					System.out.println(type + " is an invalid type.");
					System.exit(0);
				}
			}else if(args[i].equals("-port")){
				port = Integer.parseInt(args[i+1]);
				if(port < 1024 || port > 65536){
					System.out.println(port + " must be in range [1024,65536]");
					System.exit(0);
					
				}
				System.out.println("Port: " + port);
			}else if(args[i].equals("-secret")){
				secret = args[i+1];
				System.out.println("Secret: " + secret);
			}else if(args[i].equals("-k")){
				k = Integer.parseInt(args[i+1]);
			}
		}
		
		
		
		if(type.equals("server")){
			System.out.println("Type: Server\n");
			new Server(port);
		}else{
			System.out.println("Type: Dealer\n");
			new Dealer(port,secret,k);
		}
	}
}
